import React from 'react';

const originalCreateElement = React.createElement;

const customCreateElement = function (type, props, ...children) {
  // 处理 r-if 指令
  if (props && props['r-if'] === false) {
    return null;
  }
  if (props && typeof props['r-if'] !== 'undefined') {
    return props['r-if'] 
      ? originalCreateElement(type, {...props, 'r-if': undefined}, ...children)
      : null;
  }

  return originalCreateElement(type, props, ...children);
};

export const applyDirectives = () => {
  // 确保只应用一次
  if (!React.__directivesApplied) {
    React.__directivesApplied = true;
    React.createElement = customCreateElement; // 实际应用覆写
  }
};